<template>
    <div>
        <h1>登录</h1>
        <table class="table">
            <tr>
                <td>用户名</td>
                <td>
                    <input type="text" v-model="data.name">
                </td>
            </tr>

            <tr>
                <td>密码</td>
                <td>
                    <input type="password" v-model="data.pwd">
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <input type="button" class="btn btn-success" value="登录" @click="login">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref} from 'vue'
import { useRouter } from 'vue-router';
const router=useRouter()

const data=ref({
    name:'',
    pwd:''
})
//登录
const login=()=>{
    axios.get("/api/User/Login",{params:data.value}).then(res=>{
        if(res.data.uid==-1){
            alert('用户名不存在');
            return;
        }
        else if(res.data.uid==-2){
            alert('密码错误');
            return;
        }
        else if(res.data.uid>0){
            alert('登录成功');
            router.push('/bfshow')
        }
    })
}
</script>

<style scoped>

</style>